package com.leokok.jts.learning.jts.core.linearref;

import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.linearref.LengthLocationMap;
import org.locationtech.jts.linearref.LinearLocation;
import org.locationtech.jts.linearref.LocationIndexedLine;

public class LengthIndexOfPointTest {

    @Test
    public void indexOfTest() throws ParseException {

        WKTReader wktReader = new WKTReader();
        Geometry lineGeo = wktReader.read("LINESTRING (115.99563000000002 31.988840000000003, 115.99574000000001 31.988850000000003, 115.99587000000001 31.988880000000005, 115.99592000000001 31.988840000000003, 115.996085 31.988766, 115.99615000000001 31.988810000000004, 115.99616000000002 31.988850000000003, 115.99622000000002 31.988880000000005, 115.99630000000002 31.988880000000005, 115.99635000000002 31.988880000000005, 115.99637000000001 31.988900000000005, 115.99638000000002 31.988920000000004, 115.996425 31.988965)");

        Coordinate point = new Coordinate(115.996073,  31.988865);

        LocationIndexedLine locationIndexedLine = new LocationIndexedLine(lineGeo);

//        double offset = 5E-4;
        double offset = lineGeo.getLength();

        LinearLocation linearLocation = LengthLocationMap.getLocation(lineGeo, offset);
        Coordinate result = locationIndexedLine.extractPoint(linearLocation);
        System.out.println(result.toString());


//        LengthIndexOfPoint
    }
}
